#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Purpose: Test fieldeditordialog.py
# Created: 02/03/2009
# $Id $
# Copyright (c) 2008,2009 by University College London
# Authors:
# Didrik Pinte --<dpinte@dipole-consulting.com>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with HydroPlatform for details.

import unittest
import wx

import support
from hydroplatform.ui.fieldtypeeditor import *
from hydroplatform.model.fields import *

class TestTableFieldEditorDialog(unittest.TestCase):
    
    def setUp(self):
        self.app = wx.PySimpleApp()
        self.table = Table()
        self.frame = TableFieldEditor(None, self.table)
    
    def test_addrow(self):
        before = self.frame.grid.GetNumberRows()        
        self.frame.add_row(u"test")
        after = self.frame.grid.GetNumberRows()
        print "Table : " + str(self.frame.table.data)
        self.assertNotEqual(before, after)
        self.assertEqual(before+1, after)
        self.assertEqual(len(self.table.rowLabels), 1)
        self.frame.Destroy()
        self.assertEqual(self.table.rowLabels[0], u"test")
        self.assertEqual(self.table.data.shape[0], 1)
        self.assertEqual(self.table.data.shape[1], 1)
        
    def test_addcol(self):
        before = self.frame.grid.GetNumberCols()
        print str(self.frame.generictable.GetNumberCols()) + "vs "+ str(self.frame.grid.GetNumberCols())
        self.frame.add_column("test", "m")
        print str(self.frame.generictable.GetNumberCols()) + "vs "+ str(self.frame.grid.GetNumberCols())
        after = self.frame.grid.GetNumberCols()
        print self.frame.table.data.shape
        print "Table : " + str(self.frame.table.data)
        self.assertNotEqual(before, after)
        self.assertEqual(before+1, after)


if __name__=='__main__':
    print "Testing TableFieldEditor"
    app = wx.PySimpleApp()
    t = Table()
    dialog = TableFieldEditor(None, t)
    dialog.Show()
    app.MainLoop()
    print "Table is %s" % t.data